/*
 * Created by JFormDesigner on Mon May 23 16:02:48 CST 2022
 */

package jw3.c10.view;

import java.awt.event.*;

import jw3.c10.model.Userinfo;
import jw3.c10.utils.DBConnection;

import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 * @author Brainrain
 */
public class Register extends JFrame {
    public Register() {
        initComponents();
        setSize(600,550);
        setVisible(true);
        setTitle("云卡用户注册");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        ImageIcon imgIcon=new ImageIcon("images\\q.jpg");
        JLabel im=new JLabel();
        im.setIcon(imgIcon);
        im.setBounds(0,0,600,550);
        imgIcon.setImage(imgIcon.getImage().
                getScaledInstance(700,600,1));
        this.add(im);

    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
//
        this.dispose();

    }

    private void button2MouseClicked(MouseEvent e) {
        // TODO add your code here
//        确定
        Userinfo u=new Userinfo();
        u.setUserName(textField6.getText());
        u.setAccount(textField7.getText());
        u.setPwd(textField8.getText());
        u.setJueisdiction(Integer.parseInt(textField9.getText()));

        //3、sql语句
        String sql="insert userinfo VALUES(0,?,?,?,?)";
        Connection conn= null;
        try {
            conn = DBConnection.getConnection();
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1,u.getUserName());
            ps.setString(2,u.getAccount());
            ps.setString(3,u.getPwd());
            ps.setInt(4,u.getJueisdiction());

            if (ps.executeUpdate()>0){
                JOptionPane.showMessageDialog(null,"添加成功!");
            }else{
                JOptionPane.showMessageDialog(null,"添加失败!");
            }
            DBConnection.close(null,ps,conn);
        } catch (Exception ex) {
            ex.printStackTrace();
        }



    }




    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        textField6 = new JTextField();
        label6 = new JLabel();
        button2 = new JButton();
        label7 = new JLabel();
        textField7 = new JTextField();
        label8 = new JLabel();
        textField8 = new JTextField();
        label4 = new JLabel();
        textField9 = new JTextField();
        button1 = new JButton();

        //======== this ========
        setTitle("aa");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);
        contentPane.add(textField6);
        textField6.setBounds(95, 90, 110, textField6.getPreferredSize().height);

        //---- label6 ----
        label6.setText("\u540d\u5b57\uff1a");
        label6.setForeground(Color.white);
        contentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(35, 90), label6.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u786e\u5b9a");
        button2.setForeground(Color.black);
        button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button2MouseClicked(e);
            }
        });
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(50, 285), button2.getPreferredSize()));

        //---- label7 ----
        label7.setText("\u8d26\u53f7\uff1a");
        label7.setForeground(Color.white);
        contentPane.add(label7);
        label7.setBounds(new Rectangle(new Point(35, 145), label7.getPreferredSize()));
        contentPane.add(textField7);
        textField7.setBounds(95, 140, 110, textField7.getPreferredSize().height);

        //---- label8 ----
        label8.setText("\u5bc6\u7801\uff1a");
        label8.setForeground(Color.white);
        contentPane.add(label8);
        label8.setBounds(new Rectangle(new Point(35, 190), label8.getPreferredSize()));
        contentPane.add(textField8);
        textField8.setBounds(95, 185, 115, textField8.getPreferredSize().height);

        //---- label4 ----
        label4.setText("\u7c7b\u578b\uff1a");
        label4.setForeground(Color.white);
        contentPane.add(label4);
        label4.setBounds(30, 235, 50, label4.getPreferredSize().height);
        contentPane.add(textField9);
        textField9.setBounds(95, 230, 115, 30);

        //---- button1 ----
        button1.setText("\u53d6\u6d88");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(170, 285), button1.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents


    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTextField textField6;
    private JLabel label6;
    private JButton button2;
    private JLabel label7;
    private JTextField textField7;
    private JLabel label8;
    private JTextField textField8;
    private JLabel label4;
    private JTextField textField9;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
    private  static Vector<Vector<Object>> data;

}
